<?php
include ('inc/common.inc.php');

if(isset($_POST['sub']))
{
	if(VerifyLoginUsername($_POST['username']) & VerifyPassword($_POST['password']))
	{
		$password = md5($_POST['password']);
		$cookietime = ($_POST['cookietime'] ? 3600*24*365 : 0);
		$sql = "SELECT * FROM `{$pre}userinfo_basic` WHERE `username`='{$_POST['username']}' AND `password`='{$password}'";
		$rst = $db->query($sql);
		if($row = $db->fetch_array($rst))
		{
			$currentTime = mktime();
			$lastLoginTime = date("Y-m-d H:i:s", $row['lastlogintime']);
			$sql="UPDATE `{$pre}userinfo_basic` SET `lastlogintime` = '{$currentTime}' WHERE `username` = '{$row[username]}' LIMIT 1 ";
			$db->query($sql);
			SetLoginCookie('lncg',$cookietime);
			$Log = ParseLoginCookie('lncg');
			message("网页消息", "{$row['realname']}欢迎您，三秒后自动跳转至个人中心,您上次登录时间为{$lastLoginTime}","search.php");
		}
		else
		{
			message("网页消息", "对不起，用户名或者密码错误，请重新登录","login.php");
		}
	}
	else
	{
		message("网页消息", "对不起，用户名或者密码不合法，请重新登录","login.php");
	}
}
include template('login.html');
?>
